/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.*;

/**
 * @author Administrator
 */
public class Main extends MIDlet {

    private Display display;
    private LuckyCoinCanvas luckyCoinCanvas;
    private MainCanvas mainCanvas;

    public void startApp() {
        display = Display.getDisplay(this);
        displayMainCanvas(0);
    }

    public void pauseApp() {
    }

    public void call(String number) {
        try {
            platformRequest("tel:" + number);
        } catch (Exception ex) {
        }
    }

    public void destroyApp(boolean unconditional) {
        DataTransfer.releaseConnection();
        notifyDestroyed();
    }

    public void displayMainCanvas(int id) {
        mainCanvas = new MainCanvas(this);
        mainCanvas.initObject(id);
        mainCanvas.start();
        display.setCurrent(mainCanvas);
    }

    public void disposeMainCanvas() {
        if (mainCanvas != null) {
            new Thread(new Runnable() {

                public void run() {
                    while (mainCanvas.isShown()) {
                    }
                    mainCanvas.disposeObject();
                    mainCanvas = null;
                }
            }).start();
        }

    }

    public void disposeLuckyCoin() {
        if (luckyCoinCanvas != null) {
            new Thread(new Runnable() {

                public void run() {
                    while (luckyCoinCanvas.isShown()) {
                    }
                    luckyCoinCanvas.disposeObject();
                    luckyCoinCanvas = null;
                }
            }).start();
        }

    }

    public void displayLuckyCoin() {
        luckyCoinCanvas = new LuckyCoinCanvas(this);
        luckyCoinCanvas.start();
        display.setCurrent(luckyCoinCanvas);
    }

    void openWeb(String link) {
        try {
            Debug.d("open web:" + link);
            this.platformRequest(link);
        } catch (ConnectionNotFoundException ex) {
        }
    }
}
